// To log out
function logout(){
  if(!window.confirm('Are you sure to quit?')) return ;
  else{
    localStorage.clear();
    ajaxRequest("../php/logout.php", 'get', null, function(){
      alert(this.responseText);
      location.replace('../index.html');
    }, function(){
      alert("ERROR" + this.responseText);
    });
    
  }
  
}

window.onload = function(){
  // modify header
  function isLogin(){
    if(localStorage.hasOwnProperty("UserName")){
        document.getElementById("login").style.display = 'none';
        document.getElementById("login-out").style.display = 'block';
        document.getElementById("profile").style.display = 'block';
        document.querySelector("#profile a").innerHTML = 'User: ' + localStorage.getItem('UserName');
    }
    else{
        document.getElementById("login-out").style.display = 'none';
        document.getElementById("login").style.display = 'block';
        document.getElementById("profile").style.display = 'none';
    }
}
isLogin();
}